package com.llkj.qingnianguoxue.adapter;

import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chauthai.swipereveallayout.SwipeRevealLayout;
import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.bean.CostRecordListBean;
import com.llkj.qingnianguoxue.util.DisplayUtil;

import java.util.List;

/**
 * 消费记录
 */
public class CostRecordAdapter extends BaseQuickAdapter<CostRecordListBean.CostRecordBean, BaseViewHolder> {

    public CostRecordAdapter(int layoutResId, List<CostRecordListBean.CostRecordBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, CostRecordListBean.CostRecordBean item) {
        baseViewHolder.setText(R.id.tv_title, item.getName());
        baseViewHolder.setText(R.id.tv_time, item.getAddtime());

        TextView tvMoney = baseViewHolder.getView(R.id.tv_record_money);
        String temp = "";
        if ("1".equals(item.getGenre())) {// 类型 1 消费 2 充值
            temp = "-";
            tvMoney.setTextColor(mContext.getResources().getColor(R.color.blue3989ff));
        } else {
            temp = "+";
            tvMoney.setTextColor(mContext.getResources().getColor(R.color.colorFE4A49));
        }
        tvMoney.setText(temp + item.getMoney());

        SwipeRevealLayout swipeDelGroup = baseViewHolder.getView(R.id.swipeDelGroup);
        TextView tvDelItem = baseViewHolder.getView(R.id.tvDelItem);
        tvDelItem.getLayoutParams().height = DisplayUtil.dip2px(mContext, 75);
        baseViewHolder.addOnClickListener(R.id.tvDelItem);
        swipeDelGroup.close(true);
        swipeDelGroup.setSwipeListener(new SwipeRevealLayout.SimpleSwipeListener() {
            @Override
            public void onClosed(SwipeRevealLayout view) {
                super.onClosed(view);
            }

            @Override
            public void onOpened(SwipeRevealLayout view) {
                super.onOpened(view);
            }
        });
    }

}
